package com.example.amazing_wangjj.config;


import com.example.amazing_wangjj.store.MongoChatMemoryStore;
import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
//记忆区提供者配置类，助手注解绑定本类，在调用chat方法时，会从本类中获取记忆区对象，
public class MongoDbStoreMemery {

    //持久化类，封装一些与mongodb交互的方法
    @Autowired
    private MongoChatMemoryStore mongoChatMemoryStore;

    //自定义记忆区提供者,在助手注解@AiService中使用，方法名对应注解中的参数值
    @Bean
    ChatMemoryProvider chatMemoryProviderByMongodb() {
        //构建一个记忆区MessageWindowChatMemory对象,指定自定义的持久化类
        return memoryId -> MessageWindowChatMemory.builder()
                .id(memoryId)
                .maxMessages(30)
                .chatMemoryStore(mongoChatMemoryStore)//配置持久化对象
                .build();
    }
}
